#include "SeptDC.h"
// Initialization of the game
void Initialize(septdc& sv)
{
	for (int i = 0; i < NB_MAX_PLAYER; i++)
	{
		Initialize(sv.players[i]);
	}

	Initialize(sv.gameDeck);
	for (int i = 0; i < MAX_CARD_OFF_TYPE; i++)
	{
		Initialize(sv.diamonds[i]);
		Initialize(sv.clubs[i]);
		Initialize(sv.spades[i]);
		Initialize(sv.hearts[i]);
	}
}

// Add a card to ther right array of cards on the table at the right index
void AddCardToType(septdc& sv, card& c)
{
	// Switch on the kind of the card to find the right array
	switch (c.kind)
	{
	case HEART:
	{
		// Add a card to the 1st place of the array 
		if (sv.nbCardsInHeart == 0 && c.value == START_VALUE)
		{
			sv.nbCardsInHeart++;
			sv.hearts[START_INDEX] = c;
		}
		else
		{
			// If the value is higher place it to the right
			if (c.value > START_VALUE)
			{
				sv.heartUpIndex++;
				sv.hearts[START_INDEX + sv.heartUpIndex] = c;

			}
			// If the value is lower place it to the left
			else
			{
				sv.heartDownIndex++;
				sv.hearts[START_INDEX - sv.heartDownIndex] = c;
			}
		}
		break;
	}

	case DIAMOND:
	{
		// Add a card to the 1st place of the array 
		if (sv.nbCardsInDiamonds == 0 && c.value == START_VALUE)
		{
			sv.nbCardsInDiamonds++;
			sv.diamonds[START_INDEX] = c;
		}
		else
		{
			// If the value is higher place it to the right
			if (c.value > START_VALUE)
			{
				sv.diamondUpIndex++;
				sv.diamonds[START_INDEX + sv.diamondUpIndex] = c;
			}
			// If the value is lower place it to the left
			else
			{
				sv.diamondDownIndex++;
				sv.diamonds[START_INDEX - sv.diamondDownIndex] = c;
			}
		}
		break;
	}

	case CLUB:
	{
		// Add a card to the 1st place of the array 
		if (sv.nbCardsInClubs == 0 && c.value == START_VALUE)
		{
			sv.nbCardsInClubs++;
			sv.clubs[START_INDEX] = c;
		}
		else
		{
			// If the value is higher place it to the right
			if (c.value > START_VALUE)
			{
				sv.clubUpIndex++;
				sv.clubs[START_INDEX + sv.clubUpIndex] = c;

			}
			// If the value is lower place it to the left
			else
			{
				sv.clubDownIndex++;
				sv.clubs[START_INDEX - sv.clubDownIndex] = c;
			}
		}
		break;
	}

	case SPADE:
	{
		// Add a card to the 1st place of the array 
		if (sv.nbCardsInSpades == 0 && c.value == START_VALUE)
		{
			sv.nbCardsInSpades++;
			sv.spades[START_INDEX] = c;
		}
		else
		{
			// If the value is higher place it to the right
			if (c.value > START_VALUE)
			{
				sv.spadeUpIndex++;
				sv.spades[START_INDEX + sv.spadeUpIndex] = c;
			}
			// If the value is lower place it to the left
			else
			{
				sv.spadeDownIndex++;
				sv.spades[START_INDEX - sv.spadeDownIndex] = c;
			}
		}
		break;
	}

	default:
		break;
	}
}

// Dsplay of the game table
void Display(septdc& sv)
{
	// Array for the Diamond section
	for (int i = 0; i < CARD_HEIGHT_VISUAL; i++)
	{
		for (int j = 0; j < MAX_CARD_OFF_TYPE; j++)
		{
			// Checks if the current card being processed is the last one in the array
			// If it is, it only shows half of the width of the card
			// The same occurs in the 3 other arrays below
			if (j == MAX_CARD_OFF_TYPE -1 )
			{
				Display(sv.diamonds[j], i, CARD_WIDTH_VISUAL);
			}
			else
			{
				Display(sv.diamonds[j], i, CARD_WIDTH_VISUAL / 2);
			}
		}
		std::cout << std::endl;
	}
	
	// Array for the Clubs section
	for (int i = 0; i < CARD_HEIGHT_VISUAL; i++)
	{
		for (int j = 0; j < MAX_CARD_OFF_TYPE; j++)
		{
			if (j == MAX_CARD_OFF_TYPE - 1)
			{
				Display(sv.clubs[j], i, CARD_WIDTH_VISUAL);
			}
			else
			{
				Display(sv.clubs[j], i, CARD_WIDTH_VISUAL / 2);
			}
		}
		std::cout << std::endl;
	}

	// Array for the Spades section	
	for (int i = 0; i < CARD_HEIGHT_VISUAL; i++)
	{
		for (int j = 0; j < MAX_CARD_OFF_TYPE; j++)
		{
			if (j == MAX_CARD_OFF_TYPE - 1)
			{
				Display(sv.spades[j], i, CARD_WIDTH_VISUAL);
			}
			else
			{
				Display(sv.spades[j], i, CARD_WIDTH_VISUAL / 2);
			}
		}
		std::cout << std::endl;
	}
	
	// Array for the Hearts section
	for (int i = 0; i < CARD_HEIGHT_VISUAL; i++)
	{
		for (int j = 0; j < MAX_CARD_OFF_TYPE; j++)
		{
			if (j == MAX_CARD_OFF_TYPE - 1)
			{
				Display(sv.hearts[j], i, CARD_WIDTH_VISUAL);
			}
			else
			{
				Display(sv.hearts[j], i, CARD_WIDTH_VISUAL / 2);
			}
		}
		std::cout << std::endl;
	}
}

// Verify if the card can be played 
bool CheckPlayability(septdc& sv, card& c)
{
	bool playable = false;

	switch (c.kind)
	{
	case HEART:
	{
		// Verify if the card is a 7 and if the 7 of diamond is out
		if (sv.diamonds[c.value - 1].value == c.value && c.value == START_VALUE)
		{
			playable = true;
			sv.firstCardPLayedHeart = true;
		}
		// Verify if the value is higher than 7 and if the 7 of the type have been played
		else if (c.value > START_VALUE && sv.firstCardPLayedHeart)
		{
			// Verify if the card is not a K and if it have been played in diamond
			if (c.value != 13 && sv.diamonds[c.value - 1].value == c.value )
			{
				// Verify if the card before is there
				if (sv.diamonds[c.value - 2].value = (c.value - 1))
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			// Verify if the card is a K and the 7 of the type is out
			else if (c.value == KING && sv.firstCardPLayedHeart)
			{
				// Verify if the card K is out in diamond and if the card before have been played
				if (sv.diamonds[c.value - 1].value == c.value && sv.hearts[KING-2].value == KING-1)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		// Verify if the value is lower than 7 and if the 7 of the type have been played
		else if (c.value < START_VALUE && sv.firstCardPLayedHeart)
		{
			// Verify if the card is not a A and if it have been played in diamond
			if (c.value != ACE && sv.diamonds[c.value - 1].value == c.value )
			{
				// Verify if the card before is there
				if (sv.diamonds[c.value].value = c.value + 1)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			// Verify if the card is an Ace and the 7 of the type is out
			else if (c.value == ACE && sv.firstCardPLayedHeart)
			{
				// Verify id the card K is out in diamond and if trhe card before have been played
				if (sv.diamonds[c.value - 1].value == c.value && sv.hearts[1].value == 2)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		else
		{
			playable = false;
		}
		break;
	}

	case DIAMOND:
	{
		// If value = start value (7)
		if (c.value == START_VALUE)
		{
			playable = true;
			sv.firstCardPLayedDiamond = true;
		}
		// If value of the card is higher than the highest card in the array
		else if (c.value == sv.diamonds[START_INDEX + sv.diamondUpIndex].value + 1 && sv.firstCardPLayedDiamond)
		{
			playable = true;
		}
		// If value of the card is lower than the lowest card in the array
		else if (c.value == sv.diamonds[START_INDEX - sv.diamondDownIndex].value - 1 && sv.firstCardPLayedDiamond)
		{
			playable = true;
		}
		// No, Cannot play
		else
		{
			playable = false;
		}
		break;
	}

	case CLUB:
	{
		// Verify if the card is a 7 and if the 7 of diamond is out
		if (sv.diamonds[c.value - 1].value == c.value && c.value == START_VALUE)
		{
			playable = true;
			sv.firstCardPLayedClub = true;
		}
		// Verify if the value is higher than 7 and if the 7 of the type have been played
		else if (c.value > START_VALUE && sv.firstCardPLayedClub)
		{
			// Verify if the card is not a K and if it have been played in diamond
			if (c.value != KING && sv.diamonds[c.value - 1].value == c.value)
			{
				// Verify if the card before is there
				if (sv.diamonds[c.value - 2].value = (c.value - 1))
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			// Verify if the card is a K and the 7 of the type is out
			else if (c.value == KING && sv.firstCardPLayedClub)
			{
				// Verify if the card before is there
				if (sv.diamonds[c.value - 1].value == c.value && sv.clubs[11].value == 12)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		// Verify if the value is lower than 7 and if the 7 of the type have been played
		else if (c.value < START_VALUE && sv.firstCardPLayedClub)
		{
			// Verify if the card is not a A and if it have been played in diamond
			if (c.value != 1 && sv.diamonds[c.value - 1].value == c.value)
			{
				// Verify if the card before is there
				if (sv.diamonds[c.value].value = c.value + 1)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			// Verify if the card is a K and the 7 of the type is out
			else if (c.value == ACE && sv.firstCardPLayedClub)
			{
				// Verify id the card Ace is out in diamond and if the card before have been played
				if (sv.diamonds[c.value - 1].value == c.value && sv.clubs[ACE].value == 2)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		else
		{
			playable = false;
		}

	}
		// The algorithm to check if a card is playable is pretty much the same for all of the other 
		// Card arrays
	case SPADE:
	{
		if (sv.diamonds[c.value - 1].value == c.value && c.value == START_VALUE)
		{
			playable = true;
			sv.firstCardPLayedClub = true;
		}
		else if (c.value > START_VALUE && sv.firstCardPLayedClub)
		{
			if (c.value != KING && sv.diamonds[c.value - 1].value == c.value)
			{
				if (sv.diamonds[c.value - 2].value = (c.value - 1))
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			else if (c.value == KING && sv.firstCardPLayedClub)
			{
				if (sv.diamonds[c.value - 1].value == c.value && sv.clubs[11].value == 12)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		else if (c.value < START_VALUE && sv.firstCardPLayedClub)
		{
			if (c.value != 1 && sv.diamonds[c.value - 1].value == c.value)
			{
				if (sv.diamonds[c.value].value = c.value + 1)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
			else if (c.value == 1 && sv.firstCardPLayedClub)
			{
				if (sv.diamonds[c.value - 1].value == c.value && sv.clubs[1].value == 2)
				{
					playable = true;
				}
				else
				{
					playable = false;
				}
			}
		}
		else
		{
			playable = false;
		}

	}
	default:
		break;
	}
	return playable;
}


void Play(septdc& sv)
{
	card cardToDiscard;
	card pickFromPlayers;
	bool foundItDiamond = false;
	bool endGame = false;
	int startingPlayer;
	// Initialises the whole game and deck, Then shuffles and distributes the deck
	Initialize(sv);
	Shuffle(sv.gameDeck);
	Distribute(sv);
	// Checks for which player has the 7 of Diamonds
	while (foundItDiamond == false)
	{
		for (int i = 0; i < NB_MAX_PLAYER; i++)
		{
			for (int j = 0; j < sv.players[i].h.nbCardInHand; j++)
			{
				// Find the 7 diamond in player hands
				if (sv.players[i].h.cards[j].value == 7 && sv.players[i].h.cards[j].kind == 4)
				{
					std::cout << "Player " << i + 1 << " " << "Hand" << std::endl;
					
					// Forces the player to place it on the table
					do
					{
						Display(sv.players[i]);
						cardToDiscard = Discard(sv.players[i].h);
						if (CheckPlayability(sv, cardToDiscard) == false)
						{
							// If the card cannot be played, it is placed back into the player's hand
							std::cout << "This card cannot be played" << std::endl;
							AddCard(sv.players[i].h, cardToDiscard);
						}
					} while (!CheckPlayability(sv, cardToDiscard));
					
					// Keeps track of which player had the 7 of diamonds
					startingPlayer = i;
					foundItDiamond = true;
				}
			}
		}
	}
	// Adds the card to its corresponding type
	 AddCardToType(sv, cardToDiscard);
	 do
	 {
		 switch (startingPlayer)
		 {
		 //	Checks which player started. Depending on which one had the 7 of Diamonds, the next one is asked
		 // To play. Each case is nearly identical other than the starting player.
		 case 0:
		 {
			 Display(sv);
			 std::cout << "Player 2" << std::endl;
			 Display(sv.players[1]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[1]) == false)
			 {
				 std::cout << "Player 3's hand." << std::endl;
				 Display(sv.players[2]);
				 std::cout << "Choose a card to give to Player 2: " << std::endl;
				 pickFromPlayers = Discard(sv.players[2].h);
				 AddCard(sv.players[1].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[1].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[1].h, cardToDiscard);
						 Display(sv.players[1].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			
			 Display(sv);
			 std::cout << "Player 3" << std::endl;
			 Display(sv.players[2]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[2]) == false)
			 {
				 std::cout << "Player 1's hand." << std::endl;
				 Display(sv.players[0]);
				 std::cout << "Choose a card to give to Player 3: " << std::endl;
				 pickFromPlayers = Discard(sv.players[0].h);
				 AddCard(sv.players[2].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[2].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[2].h, cardToDiscard);
						 Display(sv.players[2].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 
			 Display(sv);
			 std::cout << "Player 1" << std::endl;
			 Display(sv.players[0]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[0]) == false)
			 {
				 std::cout << "Player 2's hand." << std::endl;
				 Display(sv.players[1]);
				 std::cout << "Choose a card to give to Player 1: " << std::endl;
				 pickFromPlayers = Discard(sv.players[1].h);
				 AddCard(sv.players[0].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[0].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[0].h, cardToDiscard);
						 Display(sv.players[0].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 
			 break;
		 }
		 case 1:
		 {
			 Display(sv);
			 std::cout << "Player 3" << std::endl;
			 Display(sv.players[2]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[2]) == false)
			 {
				 std::cout << "Player 1's hand." << std::endl;
				 Display(sv.players[0]);
				 std::cout << "Choose a card to give to Player 3: " << std::endl;
				 pickFromPlayers = Discard(sv.players[0].h);
				 AddCard(sv.players[2].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[2].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[2].h, cardToDiscard);
						 Display(sv.players[2].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }

			 Display(sv);
			 std::cout << "Player 1" << std::endl;
			 Display(sv.players[0]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[0]) == false)
			 {
				 std::cout << "Player 2's hand." << std::endl;
				 Display(sv.players[1]);
				 std::cout << "Choose a card to give to Player 1: " << std::endl;
				 pickFromPlayers = Discard(sv.players[1].h);
				 AddCard(sv.players[0].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[0].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[0].h, cardToDiscard);
						 Display(sv.players[0].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 
			 Display(sv);
			 std::cout << "Player 2" << std::endl;
			 Display(sv.players[1]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[1]) == false)
			 {
				 std::cout << "Player 3's hand." << std::endl;
				 Display(sv.players[2]);
				 std::cout << "Choose a card to give to Player 2: " << std::endl;
				 pickFromPlayers = Discard(sv.players[2].h);
				 AddCard(sv.players[1].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[1].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[1].h, cardToDiscard);
						 Display(sv.players[1].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 break;
		 }
		 case 2:
		 {
			 Display(sv);
			 std::cout << "Player 1" << std::endl;
			 Display(sv.players[0]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[0]) == false)
			 {
				 std::cout << "Player 2's hand." << std::endl;
				 Display(sv.players[1]);
				 std::cout << "Choose a card to give to Player 1: " << std::endl;
				 pickFromPlayers = Discard(sv.players[1].h);
				 AddCard(sv.players[0].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[0].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[0].h, cardToDiscard);
						 Display(sv.players[0].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 Display(sv);
			 std::cout << "Player 2" << std::endl;
			 Display(sv.players[1]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[1]) == false)
			 {
				 std::cout << "Player 3's hand." << std::endl;
				 Display(sv.players[2]);
				 std::cout << "Choose a card to give to Player 2: " << std::endl;
				 pickFromPlayers = Discard(sv.players[2].h);
				 AddCard(sv.players[1].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[1].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[1].h, cardToDiscard);
						 Display(sv.players[1].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }

			 Display(sv);
			 std::cout << "Player 3" << std::endl;
			 Display(sv.players[2]);
			 // Check if the player can play otherwise he pick in the next player's hand
			 if (CheckHandPlayability(sv, sv.players[2]) == false)
			 {
				 std::cout << "Player 1's hand." << std::endl;
				 Display(sv.players[0]);
				 std::cout << "Choose a card to give to Player 3: " << std::endl;
				 pickFromPlayers = Discard(sv.players[0].h);
				 AddCard(sv.players[2].h, pickFromPlayers);
			 }
			 // Play a card
			 else
			 {
				 do
				 {
					 cardToDiscard = Discard(sv.players[2].h);
					 if (CheckPlayability(sv, cardToDiscard) == false)
					 {
						 std::cout << "This card cannot be played. Please pick another one." << std::endl;
						 AddCard(sv.players[2].h, cardToDiscard);
						 Display(sv.players[2].h);
					 }
				 } while (!CheckPlayability(sv, cardToDiscard));

				 AddCardToType(sv, cardToDiscard);
				 endGame = CheckVictory(sv);
			 }
			 
			 break;
		 }
		 default:
			 break;
		 }
	 } while (!endGame);
}

// Distribute the full deck to the players.
void Distribute(septdc& sv)
{
	int j = 0;
	while (sv.gameDeck.nbCardToDistribute > EMPTY_DECK -1 )
	{
		// Adds each card to each player
		AddCard(sv.players[j].h, sv.gameDeck.cards[sv.gameDeck.nbCardToDistribute]);
		sv.gameDeck.nbCardToDistribute--;

		j++;
		// Switches from player 3 to 1 if the player's index is higher than the number
		// of max players
		if (j == NB_MAX_PLAYER)
		{
			j = 0;
		}
	}
	//Removes any abherrant cards from the hand.
	for (int i = 0; i < NB_MAX_PLAYER; i++)
	{
		for (int j = 0; j <= sv.players[i].h.nbCardInHand; j++)
		{
			if (sv.players[i].h.cards[j].kind != 3 &&
				sv.players[i].h.cards[j].kind != 4 &&
				sv.players[i].h.cards[j].kind != 5 &&
				sv.players[i].h.cards[j].kind != 6)
			{
				sv.players[i].h.nbCardInHand--;
			}
		}
	}
}

// Check which player wins
bool CheckVictory(septdc& sv)
{
	bool doesItWin = false;

	if (sv.players[0].h.nbCardInHand == WIN_CONDITION)
	{
		std::cout << "Player one wins!" << std::endl;
		doesItWin = true;
	}
	else if (sv.players[1].h.nbCardInHand == WIN_CONDITION)
	{
		std::cout << "Player two wins!" << std::endl;
		doesItWin = true;
	}
	else if (sv.players[2].h.nbCardInHand == WIN_CONDITION)
	{
		std::cout << "Player three wins!" << std::endl;
		doesItWin = true;
	}
	else
		doesItWin = false;
	return doesItWin;
}

// Check if the player can play or not 
bool CheckHandPlayability(septdc& sv, player& p)
{
	bool canPlay;
	int cardToPlay = 0;

	for (int i = 0; i < p.h.nbCardInHand; i++)
	{
		if (CheckPlayability(sv, p.h.cards[i]))
		{
			canPlay = true;
			cardToPlay++;
		}
		if (cardToPlay == 0)
		{
			canPlay = false;
		}
	}
	std::cout << "You have " << cardToPlay << " possible cards to play." << std::endl;
	return canPlay;
}